package com.example.last.controller;

import com.example.last.common.Result;
import com.example.last.entity.Audit;
import com.example.last.entity.Params;
import com.example.last.service.AuditService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@RequestMapping("/audit")
@RestController
public class AuditController {
    @Resource
    private AuditService AuditService;
    
    @GetMapping("/search")
    public Result findBySearch(@Param("params") Params params){
        PageInfo<Audit> info = AuditService.findBySearch(params);
        return Result.success(info);
    }

    //新增信息
    @PostMapping
    public Result save(@RequestBody Audit Audit){
        if(Audit.getId() == null){
            AuditService.add(Audit);
        }else{
            AuditService.update(Audit);
        }
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        AuditService.delete(id);
        return Result.success();
    }


}
